<script setup lang="ts">
import { useRouter } from 'vue-router';
import {useUsererStore} from '@/stores/user'
import { ElMessage } from 'element-plus';
import { onMounted } from 'vue';
import { useBlogStore } from '@/stores/blogStore'
const router = useRouter()
const userStore = useUsererStore()
const exchange = () => {
    if(!userStore.userInfo?.username) {
        ElMessage.warning('请先登录')
        return
    }
    router.push('/newblog')
}

const BlogStore = useBlogStore()
onMounted(() => {
    // 登录后才查询是否签到
    if(userStore.userInfo?.username){
        BlogStore.seachSAignin() // 查询打卡记录
    }
})
</script>
<template>
    <div v-bind="$attrs" class="bg-white overflow-hidden border mt-6">
        <div class="text-base px-6 py-5 border-b text-gray-800">社区小贴</div>
        <div class="text-base px-6 py-5 border-b text-gray-800">
            一群热爱技术的骚年，友好交流，热爱和平
        </div>
        <div class="text-base px-6 py-5 flex justify-center bg-slate-50 text-gray-800">
            <el-button class="bg-primary" @click="exchange" type="primary">发帖交流</el-button>
            <el-button :disabled="BlogStore.isSignin" class="bg-success" @click="BlogStore.signin" type="success">{{BlogStore.isSignin ? '签到后1天可再签' : '签到打卡'}}</el-button>
        </div>
    </div>
</template>